package com.kitty.game.equip.handler;

import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.bag.message.RespIconCartoon;
import com.kitty.game.utils.AsktaoUtil;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Component;
import com.kitty.game.equip.handler.EquipIdentifyHandler;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Random;

import static com.kitty.game.utils.NotifyModules.NOTIFY_EQUIP_IDENTIFY_GEM;

/**
 * 宝石鉴定
 */
@Component("EquipIdentityGem")
public class EquipIdentityGemHandler extends EquipIdentifyHandler {
    @Override
    public String doUpgrade(Role role, Object... params) {
        RoleEquip roleEquip = (RoleEquip) params[0];
        short newPos = (short) params[1];
        /**扣除金钱*/
        int needCash = needCash(roleEquip.queryLevel(), roleEquip.queryEquipPos(false));
        roleService.subtractMoney(role, needCash);

        ArrayList<String> arrayList = new ArrayList<>();
        if (roleEquip.queryLevel() >= 110) {
            arrayList.add("红宝石");
            arrayList.add("芙蓉石");
        } else if (roleEquip.queryLevel() >= 80) {
            arrayList.add("芙蓉石");
            arrayList.add("蓝松石");
        } else {
            arrayList.add("蓝松石");
        }

        Random random = new Random();
        int index = random.nextInt(arrayList.size());
        RoleEquip newEquip = equipService.identityGem(role, arrayList.get(index), newPos,1);

        MessagePusher.pushMessage(role, new RespIconCartoon(newEquip.getName()));

        refreshRoleEquip(role,newEquip);
        roleService.addAchieveScore(role,"301049");
        pushOperateResult(role, UPGRADE_SUCCESS);
        return MessageFormat.format(SUCCESS, AsktaoUtil.getMoneyFormat(needCash), newEquip.getName());
    }

    @Override
    int getNotifyType() {
        return NOTIFY_EQUIP_IDENTIFY_GEM;
    }

    @Override
    public int needCash(short level, int pos) {
        int needCash = 0;
        if (level == 130) {
            needCash = 1240000;
        }else if (level == 120) {
            needCash = 1120000;
        } else if (level == 110) {
            needCash = 900000;
        } else if (level == 100) {
            needCash = 670000;
        } else if (level == 90) {
            needCash = 490000;
        } else if (level == 80) {
            needCash = 380000;
        } else if (level == 70) {
            needCash = 280000;
        }
        return needCash > 0 ? needCash : 0;
    }


    @Override
    public String getUpdateTypeStr() {
        return "equip_identity_gem";
    }
}
